What is @turf/clean-coords?
@turf/clean-coords is a module from the Turf.js library that is used to clean coordinates in GeoJSON data. It removes redundant coordinates, such as consecutive duplicate points, and ensures the data is optimized for further processing or visualization.
What are @turf/clean-coords's main functionalities?
Remove Redundant Coordinates
This feature removes consecutive duplicate coordinates from a GeoJSON LineString. The input line has redundant points which are removed in the cleaned output.
const turf = require('@turf/turf');
const line = turf.lineString([
[0, 0], [1, 1], [1, 1], [2, 2], [3, 3], [3, 3], [4, 4]
]);
const cleaned = turf.cleanCoords(line);
console.log(cleaned);
Clean Polygon Coordinates
This feature cleans redundant coordinates from a GeoJSON Polygon. The input polygon has duplicate points which are removed in the cleaned output.
const turf = require('@turf/turf');
const polygon = turf.polygon([
[
[0, 0], [1, 1], [1, 1], [1, 0], [0, 0], [0, 0]
]
]);
const cleaned = turf.cleanCoords(polygon);
console.log(cleaned);
Other packages similar to @turf/clean-coords
simplify-geojson
The simplify-geojson package is used to simplify GeoJSON data by reducing the number of points in geometries while preserving the overall shape. Unlike @turf/clean-coords, which focuses on removing redundant points, simplify-geojson reduces the complexity of the geometry.
geojson-rewind
The geojson-rewind package ensures that GeoJSON polygons have the correct winding order. While @turf/clean-coords removes redundant coordinates, geojson-rewind focuses on correcting the order of coordinates to ensure they follow the right-hand rule.
@turf/clean-coords
cleanCoords
Removes redundant coordinates from any GeoJSON Geometry.
Parameters
geojson
(Geometry | Feature) Feature or Geometryoptions
Object Optional parameters (optional, default {}
)
options.mutate
boolean allows GeoJSON input to be mutated (optional, default false
)
Examples
var line = turf.lineString([[0, 0], [0, 2], [0, 5], [0, 8], [0, 8], [0, 10]]);
var multiPoint = turf.multiPoint([[0, 0], [0, 0], [2, 2]]);
turf.cleanCoords(line).geometry.coordinates;
turf.cleanCoords(multiPoint).geometry.coordinates;
Returns (Geometry | Feature) the cleaned input Feature/Geometry
This module is part of the Turfjs project, an open source
module collection dedicated to geographic algorithms. It is maintained in the
Turfjs/turf repository, where you can create
PRs and issues.
Installation
Install this module individually:
$ npm install @turf/clean-coords
Or install the Turf module that includes it as a function:
$ npm install @turf/turf